Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL-2288: Create mongosqltranslate integration tests #251

Open
wants to merge 25 commits into
base: on-prem-eap
Choose a base branch
from

Conversation

EthanHardyMongo
Copy link
Collaborator

@EthanHardyMongo EthanHardyMongo commented Oct 14, 2024

This PR corrects the changes made in SQL-2291 and adds integration tests.

The path for libmongosqltranslate will instead be modified in this follow up ticket: https://jira.mongodb.org/browse/SQL-2403

Evergreen patch with everything passing: https://spruce.mongodb.com/version/670ee37a1d7c8900078da0ec/tasks?page=0&sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC&statuses=success&variant=%5Eubuntu2204%24

@EthanHardyMongo EthanHardyMongo marked this pull request as ready for review October 14, 2024 20:45
let command = CheckDriverVersion::new(DRIVER_ODBC_VERSION.clone());
let command = CheckDriverVersion::new(DRIVER_METRICS_VERSION.clone());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DRIVER_ODBC_VERSION wasn't a valid semver version, so I switched to the DRIVER_METRICS_VERSION.

Comment on lines +555 to +556

let current_col_metadata_response: ResultSetSchema = if mongo_connection
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was merged into master with SQL-2374

Comment on lines +224 to 225
#[serde(tag = "command_type")]
pub enum CommandResponse {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deserialization wasn't working without this.

Comment on lines +66 to +71
pub fn load_mongosqltranslate_library(mock_library: bool) {
INIT.call_once(|| {
let library_path = if cfg!(test) {
let library_path = if mock_library {
get_mock_library_path()
} else {
get_library_path(LIBRARY_NAME)
get_library_path()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock_library is now only used by the unit test in this file; all the other tests can use the real library now, so I figured we could do this instead to make things easier.

evergreen.yml Outdated Show resolved Hide resolved
Comment on lines +108 to +109
///
/// NOTE: FLAKY TEST
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I was testing, I noticed sometimes this test would fail, so I'm guessing it's flaky. Has anyone else noticed this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I haven't noticed it. What was the error it was reporting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can see in this patch that it failed. I'm not sure what the error is, but the exit code is 101, so I'm guessing something panicked.

Additionally, I just remembered, once I commented out that test and ran another patch, some other tests started failing with exit code 101. You can see in this patch. However, this is the only time these tests failed. Also, later on when I uncommented the test_type_listing test, it worked fine.

So I'm not really sure what's going on.

Comment on lines +15 to +16
#[test]
fn test_srv_style_uri_connection() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test requires libmongosqltranslate, so I moved it here to make testing easier.

constants/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Member

@bucaojit bucaojit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of good work. I had some suggestions.

@@ -221,7 +221,13 @@ impl MongoDatabases {
})
.unwrap()
.iter()
.filter(|&db_name| !db_name.is_empty() && !db_name.eq("admin"))
.filter(|&db_name| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this list of databases and filter is in a couple places, can we add a helper function to filter out the databases we don't want?

Comment on lines 602 to 608
if let Err(error) = result_set_schema {
// If there is an Error while deserializing the schema, we won't show any columns for it
warnings.push(error);
continue;
}

result_set_schema.unwrap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something like this to avoid the unwrap, it has similar behavior:

match result_set_schema {
    Ok(schema) => schema,
    Err(error) => {
        warnings.push(error);
        continue;
    }
}

Comment on lines +108 to +109
///
/// NOTE: FLAKY TEST
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I haven't noticed it. What was the error it was reporting?

query.push(0);

assert_eq!(
SqlReturn::ERROR,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a check for what error we're getting here. If this one is SchemaDocumentNotFoundInSchemaCollection then it would be something like:

        let error_message = get_sql_diagnostics(HandleType::SQL_HANDLE_STMT, stmt as Handle);
        assert!(
            error_message.contains("The following collection(s) were not found in the `__sql_schemas` collection"),
            "Expected error message about missing schema collection, got: {}",
            error_message
        );
        ```

query.push(0);

assert_eq!(
SqlReturn::ERROR,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here to confirm what error we get.

db.run_command(get_schema_cmd).await.unwrap(),
)
.map_err(|e| {
Error::CollectionDeserialization(collection_name.clone(), e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about an integration test that confirms we get this on a deserialization error?

}
let _ = unsafe { Box::from_raw(env_handle) };
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One test I see in the design document that I don't see implemented yet is Invalid Command.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Invalid Command tests ended up being unit tests in mongosqltranslate. Since we control the API and the driver's calls to the API, I don't think it's possible to have an integration test that has an invalid command.

Comment on lines 173 to 180
// Struct representing the ResultSetSchema.
// The `schema` field needs the alias `result_set_schema` because this struct is used to get the schema
// from the __sql_schemas collection, which stores the schema in it's `schema` field, and the libmongosqltranslate
// `translate` command, which stores the schema in it's `result_set_schema` field.
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Default)]
pub struct ResultSetSchema {
#[serde(rename = "result_set_schema")]
#[serde(alias = "result_set_schema")]
pub schema: crate::json_schema::Schema,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this wasn't failing earlier, but I fixed it and added a comment explaining what's going on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually I think it's because the error it would cause gets pushed into a warnings vector instead of causing a crash. This is probably why my tests weren't failing.

let result_set_schema: Result<ResultSetSchema> =
                                ResultSetSchema::from_sql_schemas_document(&schema_doc).map_err(
                                    |e| {
                                        Error::CollectionDeserialization(collection_name.clone(), e)
                                    },
                                );

                            match result_set_schema {
                                Ok(result_set_schema) => result_set_schema,
                                Err(error) => {
                                    // If there is an Error while deserializing the schema, we won't show any columns for it
                                    warnings.push(error);
                                    continue;
                                }
                            }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait never mind. The part of the code that would fail was never called by my tests. That's why this wasn't causing any failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants